<template>
 <div class>
   <!--查询及新增 start-->
    <el-card>   
      <!-- <div slot="header" class="clearfix">
        <span>资信评分方案设置</span>
        <el-button style="float: right; padding: 3px 0" icon="el-icon-plus" type="success" @click="addFormVisible = true">新增</el-button>
      </div> -->
      <el-form
      size="mini"
        :model="ruleForm"
        :inline="true"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <my-form-item label="评分方案名称" prop="name">
          <el-input v-model="ruleForm.name"></el-input>
        </my-form-item>
        <my-form-item label="是否生效" prop="isEnable">
          <el-select v-model="ruleForm.isEffect" placeholder="==请选择==">
            <el-option label="是" value="1"></el-option>
            <el-option label="否" value="2"></el-option>
          </el-select>
        </my-form-item>
        <my-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">查询</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
          <el-button icon="el-icon-plus" type="success" round @click="addFormVisible = true">新增</el-button>
        </my-form-item>
      </el-form>
    </el-card>
    <!--查询及新增 end-->

    <!--表单 start-->
    <el-table :data="tableData" border stripe style="width: 100%">
      <el-table-column prop="name" label="评分方案名称" width="200" align="center"></el-table-column>
      <el-table-column prop="code" label="评分方案编码" width="140" align="center"></el-table-column>
      <el-table-column prop="retionRate" label="定量比例(%)" width="120" align="center"></el-table-column>
      <el-table-column prop="determineNatureRate" label="定性比例(%)" width="120" align="center"></el-table-column>
      <el-table-column prop="isEffect" label="是否启用" width="80" align="center" :formatter="formatData"></el-table-column>
      <el-table-column prop="effectDate" label="启用日期" width="110" align="center" :formatter="dateFormatter"></el-table-column>     
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="mini" @click="levelSetting(scope.$index, scope.row)">评级设置</el-button>
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">修改</el-button>
          <el-button size="mini" @click="preview(scope.$index, scope.row)">浏览</el-button>
          <el-button size="mini" @click="handleDistribution(scope.$index, scope.row)">分配行业</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--表单 end-->

    <!--分页 start-->
    <el-card style="text-align:right;">
        <el-pagination @size-change="handleSizeChange" 
                    @current-change="handleCurrentChange" 
                    :current-page="currentPage4" 
                    :page-sizes="[10, 20, 30, 40]" 
                    :page-size="100" background 
                    layout="total, sizes, prev, pager, next" 
                    :total="400"></el-pagination>
    </el-card>
    <!--分页 end-->

    <!--新增的弹框start -->
    <el-dialog title="新增资信评分方案设置" :visible.sync="addFormVisible" width="75%" :before-close="handleClose">
      <el-card>
      <div slot="header" style="color: blue;"><span>资信评分方案设置</span></div>
      <el-form
      size="mini"
        :model="addForm"
        :inline="true"
        ref="addForm"
        label-width="100px"
        class="demo-addForm"
      >
        <my-form-item label="评分方案名称" prop="name">
          <el-input v-model="addForm.name"></el-input>
        </my-form-item>

        <my-form-item label="评分方案编码" prop="code">
          <el-input v-model="addForm.code"></el-input>
        </my-form-item>

        <my-form-item label="是否启用" prop="isEffect">
          <el-checkbox checked="true"></el-checkbox>
        </my-form-item>

        <my-form-item label="定量比例(%)" prop="retionRate">
          <el-input v-model="addForm.retionRate"></el-input>
        </my-form-item>

        <my-form-item label="定性比例(%)" prop="determineNatureRate">
          <el-input v-model="addForm.determineNatureRate"></el-input>
        </my-form-item>

        <my-form-item label="启用日期" prop="effectDate">
          <el-date-picker type="date" placeholder="选择日期" v-model="addForm.effectDate" style="width: 60%;"></el-date-picker>
        </my-form-item>

        <my-form-item label="备注" prop="remark">
          <el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="addForm.remark" style="width: 100%;"></el-input>
        </my-form-item>
      </el-form>
      </el-card>

      <el-card>
        <div slot="header" style="color: blue;"><span>指标类型</span></div> 
        <el-table :data="tableData1" border style="width: 100%">
          <el-table-column  align="center" width="80">
            <template slot="header">
             <el-button class="el-icon-circle-plus" @click.prevent="addRow()"></el-button>
            </template>
            <template slot-scope="scope">
              <el-button size="mini" type="danger" class="el-icon-remove"
              @click="handleDelete(scope.$index, scope.row)"></el-button>
          </template>
          </el-table-column>
          
          <el-table-column label="指标类型编码" align="center" width="140">
            <template slot-scope="scope">
              <el-input v-model="scope.row.code"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="指标类型名称" align="center" width="140">
            <template slot-scope="scope">
              <el-input v-model="scope.row.name"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="所属分类" align="center" width="100">
            <template slot-scope="scope">
              <el-input v-model="scope.row.type"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="启用否" align="center" width="80">
            <template slot-scope="scope">
              <el-input v-model="scope.row.enable"></el-input>
            </template>
          </el-table-column>

          <el-table-column label="备注" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.remark"></el-input>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
      <div slot="footer" class="dialog-footer">
        <el-button @click="addFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="save('addForm')">提 交</el-button>
      </div>
    </el-dialog>
    <!--新增的弹框end -->

 </div>
</template>
<script>
export default {
    data(){
        return {
          tableData: [{ 
            name: 'A计划',
            code: 200333,
            retionRate: '30%',
            determineNatureRate: '50%',
            isEffect: 1,
            effectDate: '2018-05-02'
          }, {
            name: 'B计划',
            code: 200334,
            retionRate: '35%',
            determineNatureRate: '55%',
            isEffect: 1,
            effectDate: '2018-06-02'
          }],
          tableData1: [],
          ruleForm: {
            name: "",
            isEnable: ""
          },
          addForm: {
            name: "",
            isEnable: ""
          },
          currentPage4: 4,
          isEffectStatus: {"1":"是","0":"否"},
          addFormVisible: false
        }
      },
      mounted() {
        this.init();
      },
      methods: {
        dateFormatter: function (row, column) {
            let datetime = row[column.property];
            if(datetime){
                datetime = new Date(datetime);
                let y = datetime.getFullYear() + '-';
                let mon = datetime.getMonth()+1 + '-';
                let d = datetime.getDate();
                return y + mon + d;
            }
            return ''
        },

        //查询
        submitForm(formName) {
          this.$refs[formName].validate(valid => {
              if (valid) {
                  alert("submit!");
              } else {
                  return false;
              }
          });
        },
        //重置
        resetForm(formName) {
          this.$refs[formName].resetFields();
        },
        //关闭弹框
        handleClose(done) {
          this.$confirm("确认关闭？")
              .then(_ => {
                  done();
              })
              .catch(_ => {});
        },
        //新增
        save(formName){
        },
        //评级设置
        levelSetting(index, row) {
        },
        //修改
        handleEdit(index, row) {
        },
        //浏览
        preview(index, row) {
        },
        //分配行业
        handleDistribution(index, row) {
        },
        handleSizeChange(val) {
        },
        handleCurrentChange(val) {
        },
        formatData(val){
         return this.isEffectStatus[val.isEffect] 
        },
        // 增加行
        addRow() {
          var list = {
            code: this.code,
            name: this.name,
            type: this.type,
            enable: this.enable,
            remark: this.remark
          }
          this.tableData1.unshift(list)
        },
        handleDelete(index, row) {
            this.tableData1.splice(index, 1);
        },
        init(){
          this.$api.post(  "/api/biz/credit/doGetCreditSchemeList")
          .then(res => {
          console.log(res);
          if (res.retHead.code === "0000000") {
            console.log(res.retBody);
            this.tableData = res.retBody;
            this.total = res.retBody.total;
          }
        });
        }
    }
}
</script>